f = open('D:/数据分析师(DA)/全民一起玩PythonDemo/class14(1).txt','r')
p = f.readlines() # 以换行符切分的列表
# print(type(f))
# print(f)

all_words = []


for s in p:
    # 将标点全部替换为空格
    s = s.replace(',', ' ')
    s = s.replace('.', ' ')
    s = s.replace('?', ' ')
    s = s.replace('-', ' ')
    s = s.lower()
    line_words = s.split(' ')
    # print(line_words)
   
    # all_words = all_words + line_words
    all_words.extend(line_words)

# 集合去重
set_words = set(all_words)
all_words = list(set_words)
all_words.sort()

z = '\n'
# print(z.join(all_words))

f2 = open('D:/数据分析师(DA)/全民一起玩PythonDemo/class14(1)result.txt','w')
f2.write(z.join(all_words))
f2.close()    

